<template>
    <orh-table>
        <Button type="primary" size="small" @click="addSilde" style="margin-left: 20px" slot="returntosuperior" >
	      	提交教职工数据</Button>
        <Table :data="imortList" @on-selection-change="selectOne" highlight-row :columns="columns1" slot="table" ref="currentRowTable" :loading="loading"></Table>
        
    </orh-table>
</template>

<script>
    export default {
        props: {
            'imortList': Array
        },
        data() {
            return {
                TeacherList: [],
                prompt: false,
                loading: false,
                form:{
                    techer:[]
                },

                columns1: [{
                        type: "selection",
                        width: 60,
                        align: "center"
                    },
                    {
                        title: "学校",
                        width: 100,
                        key: 'A'
                    },
                    {
                        title: "年级",
                        width: 150,
                        key: 'B'
                    },
                    {
                        title: "所授科目",
                        width: 80,
                        key: 'C'
                    },
                    {
                        title: "姓名",
                        width: 120,
                        key: 'D'
                    },
                    {
                        title: "身份证号",
                        width: 120,
                        key: 'E'
                    },
                    {
                        title: "性别",
                        width: 120,
                        key: 'F'
                    },
                    {
                        title: "出生年月",
                        width: 120,
                        key: 'G'
                    },
                    {
                        title: "电子邮箱",
                        width: 120,
                        key: 'H'
                    },
                    {
                        title: "联系电话",
                        width: 120,
                        key: 'I'
                    },
                    {
                        title: "参加工作时间",
                        width: 120,
                        key: 'J'
                    },
                    {
                        title: "就任年月",
                        width: 120,
                        key: 'K'
                    },
                    {
                        title: "类型",
                        width: 120,
                        render: (h, params) => {
                            if (params.row.type == 1) {
                                return h('div', {
                                    style: {
                                        color: '#47cb89'
                                    }
                                }, '正常')
                            } else if (params.row.type == 2) {
                                return h('div', {
                                    style: {
                                        color: '#ed3f14'
                                    }
                                }, '身份证各式不对(请将不正确的数据删除)')
                            } else if (params.row.type == 3) {
                                return h('div', {
                                    style: {
                                        color: '#ed3f14'
                                    }
                                }, '身份证号码重复(请将不正确的数据删除)')
                            }
                        }
                    },
    
                    {
                        title: "操作",
                        key: "operation",
                        align: "center",
                        fixed: 'right',
                        width: 150,
                        render: (h, params) => {
                            return h("div", [
                                h(
                                    "Poptip", {
                                        props: {
                                            confirm: true,
                                            title: "您确定要删除这条数据吗?",
                                            type: "error",
                                            size: "small",
                                            placement: "left-end",
                                            transfer: true,
                                        },
                                        on: {
                                            "on-ok": () => {
                                                this.remove(params.index);
                                            }
                                        }
                                    }, [
                                        h(
                                            "Button", {
                                                props: {
                                                    type: "error",
                                                    size: "small"
                                                }
                                            },
                                            "删除"
                                        )
                                    ]
                                )
                            ]);
                        }
                    }
                ],
            };
        },
        methods: {
    
            remove(index) {   
                this.imortList.splice(index, 1)
            },
            selectOne(index) {    
                this.form.techer = []
                index.forEach((item, index) => {
                    this.form.techer.push(item);
                });
            },
            addSilde(){
                if(this.form.techer.length !=0){
                    this.$http.post('api/teacher/v1/teacher/importadd',this.form).then(val=>{
                        this.$Message.success(this.$t('add_success'));
                        this.$emit('requery',true);
                    
                }).catch(err =>{
                    this.$Message.error(this.$t('add_error'))
                });
                }else{
                    this.$Message.error('请选择提交数据');
                }
            },    
        },
    };
</script>
